/* eslint-disable no-empty-pattern */
import { api_add, api_delById, api_modifyAll, api_queryById } from '@/api/crud'

import { api_patchStatus, api_listPage } from '@/api/task'

const pathName = 'task'

const state = {}

const mutations = {}

const actions = {
  // 添加
  add({}, obj) {
    return new Promise((resolve, reject) => {
      api_add(pathName, obj)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 删除
  delById({}, id) {
    return new Promise((resolve, reject) => {
      api_delById(pathName, id)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改
  modifyAll({}, obj) {
    return new Promise((resolve, reject) => {
      api_modifyAll(pathName, obj)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 设置任务状态
  patchStatus({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_patchStatus(paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据id查询到一个对象全部资料
  queryById({}, id) {
    return new Promise((resolve, reject) => {
      api_queryById(pathName, id)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 得到所有数据列表
  listPage({}) {
    return new Promise((resolve, reject) => {
      api_listPage(pathName)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
